import { Share_fail, Share_success } from '../Type';
import moduleName from '../../common/Common'
import Clipboard from '@react-native-clipboard/clipboard';
import * as QQAPI from 'react-native-qq-lib';

const share_info = {
    type: 'text',
    text: '分享内容',
}

const Share_qq = () => {
    return (dispatch) => {
        QQAPI.isQQInstalled()
            .then(instll => {
                if (instll) {
                    QQAPI.shareToQQ(share_info)
                        .then(e => {
                            dispatch({
                                type: Share_success,
                                msg: '分享成功'
                            })
                        })
                        .catch(e => {
                            dispatch({
                                type: Share_fail,
                                msg: '分享失败' + e
                            })
                        })
                } else {
                    dispatch({
                        type: Share_fail,
                        msg: '分享失败，未安装QQ'
                    })
                }
            })
            .catch(e => {
                dispatch({
                    type: Share_fail,
                    msg: '分享失败' + e
                })
            })
    }
}

const Share_qq_zone = () => {
    return (dispatch) => {
        QQAPI.isQQInstalled()
            .then(instll => {
                if (instll) {
                    QQAPI.shareToQzone(share_info)
                        .then(e => {
                            console.log('???');
                            console.log(e);
                        })
                        .catch(e => {
                            console.log('!!!');
                            console.log(e);
                        })
                } else {
                    dispatch({
                        type: Share_fail,
                        msg: '分享失败，未安装QQ'
                    })
                }
            })
            .catch(e => {
                dispatch({
                    type: Share_fail,
                    msg: '分享失败' + e
                })
            })
    }
}

const Share_qq_zone_lib = () => {
    QQAPI.shareToQzone({
        type: 'text',
        text: "分享内容",
    })
        .then(e => {
            console.log('???');
        })
        .catch(e => {
            console.log(JSON.stringify(e));
        })
}

// 点击复制
const Share_copyShare_= ()=>{
    Clipboard.setString('hello world');
}

export {
    Share_qq,
    Share_qq_zone,
    Share_qq_zone_lib,
    Share_copyShare_
}